<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
    <input type="text" id="input">
    <script>
        var arr = [];
        var searchs =  [{
                spell: 'A',
                citys: [
                    {
                        name: "阿里",
                        id: 1001
                    },
                    {
                        name: "阿拉",
                        id: 1001
                    },
                    {
                        name: "阿克",
                        id: 1001
                    }

                ]

            },
            {
                spell: 'T',
                citys: [

                    {
                        name: "天天",
                        id: 2001
                    },
                    {
                        name: "天下",
                        id: 2002
                    },
                    {
                        name: "天里",
                        id: 2003
                    }

                ]
            }
        ]
        $("#input").keyup(function(event){
            if(event.keyCode==13)
            {
                var keyword = $(this).val();
                if($(this).val()!=''){
                    searchs.forEach(item=>{
                        var citys = item.citys;
                        citys.forEach(k=>{
                            if(k.name.includes(keyword)){
                                arr.push(k);
                            }
                        })
                    })
                }
            console.log(arr);
            $(this).val('');
            }
            arr=[];
            
        })
    </script>
</body>
</html>